global with sharing class createLeadClass {

	webservice static string createLeadFromConvo(Id convoId) {
		Instagram_Conversation__c convoRecord = [SELECT Author_Full_Name__c, Author_Username__c, Author_s_Bio__c, Author_URL__c, Instagram_ID__c, Parent__c From Instagram_Conversation__c where id=:convoId]; 

		Lead leadRecord = new Lead();
		leadRecord.LastName = convoRecord.Author_Full_Name__c;
		leadRecord.Instagram_Account_Name__c = convoRecord.Author_Full_Name__c;
		leadRecord.Instagram_Username__c = convoRecord.Author_Username__c;
		leadRecord.Instagram_Bio__c = convoRecord.Author_s_Bio__c;
		leadRecord.Instagram_URL__c = convoRecord.Author_URL__c;
		leadRecord.Instagram_Id__c = convoRecord.Instagram_ID__c; 		
		
		try{
			insert leadRecord;
			
			 
			convoRecord.isLeadConverted__c = true;
			convoRecord.Related_Lead__c = leadRecord.id;
			update convoRecord;
			//return 'Instagram Post successfully converted to lead';
			return leadRecord.id;
		}catch(Exception e)
		{ 
			return 'The user is an existing lead.';
			//return 'Instagram Post lead conversion failed. The user is an existing lead.';
		}
		
		
	}

}